<?php
/**
 * 文章存档
 *
 * @package custom
 */
if (!defined('__TYPECHO_ROOT_DIR__')) exit; ?>
<?php
if(!$this->request->isAjax() || !is_pjax())
    $this->need('header.php'); ?>
    <title><?php $this->archiveTitle(array(
            'category'  =>  _t('分类：%s'),
            'search'    =>  _t('搜索：%s'),
            'tag'       =>  _t('标签：%s'),
            'author'    =>  _t('%s 发布的文章')
        ), '', ' - '); ?><?php $this->options->title(); ?></title>
    <div id="wrapper" class="clearfix">
        <div id="cover">
            <div class="cover-img" style="background-image:url('<?php if ($this->options->bgPhoto){$photo = explode(',',$this->options->bgPhoto);echo $photo[array_rand($photo,1)];}else{$this->options->themeUrl('img/header_'.rand(1,31).'.jpg');}?>')"></div>
            <div class="cover-info">
                <img class="avatar" width="72" src="<?php $this->options->avatarUrl();?>" alt="" />
                <h3><?php $this->options->title(); ?></h3>
                <p><?php $this->options->description(); ?></p>
                <div class="cover-sns">
                    <div class="btn btn-weibo">
                        <a href="javascript:void(0);"><i class="fa fa-weibo"></i></a>
                        <div class="qrcode"><img src="<?php $this->options->themeUrl('img/site.png'); ?>" alt="" /></div>
                        <div class="qrcode-arrow"></div>
                    </div>
                    <div class="btn btn-weixin">
                        <a class="" href="javascript:void(0);"><i class="fa fa-weixin"></i></a>
                        <div class="qrcode"><img src="<?php $this->options->themeUrl('img/site.png'); ?>" alt="" /></div>
                        <div class="qrcode-arrow"></div>
                    </div>
                </div>
            </div>
        </div>
        <div class="body" id="body">
            <div class="main" id="main">
                <div class="page-title">
                    <ul>
                        <li <?php if($this->is('index')): ?>class="active"<?php endif; ?>><a href="<?php $this->options->siteUrl(); ?>">最新</a></li>
                        <?php if($this->is('post')): ?>
                            <li class="active">
                                <?php $categories = $this->categories;
                                if($categories):
                                    ?>
                                    <a href="<?php _e($categories[0]['permalink']); ?>"><?php _e($categories[0]['name']); ?></a>
                                <?php endif; ?>
                            </li>
                        <?php endif; ?>
                        <?php if($this->is('archive')):?>
                            <li class="active">
                                <a href="javascript:jBlog.goTop();"><?php _e($this->getArchiveTitle()); ?></a>
                            </li>
                        <?php endif; ?>
                        <li><a href="javascript:jBlog.ajaxGetExplore();" title="<?php _e('随机显示一篇文章');?>"><?php _e('探索');?></a></li>
                        <li class="page-search">
                            <form id="search" method="post" action="./" role="search">
                                <label for="s" class="sr-only"><?php _e('搜索关键字'); ?></label>
                                <input type="text" name="s" class="text" placeholder="<?php _e('输入关键字搜索'); ?>" />
                                <button type="submit" class="submit" title="<?php _e('搜索'); ?>"><i class="fa fa-search"></i></button>
                            </form>
                        </li>
                    </ul>
                </div>
                <div class="main-inner">
                    <article class="post" itemscope itemtype="http://schema.org/BlogPosting">
                        <div class="post-header">
                            <h2 class="post-title"><?php $this->title() ?></h2>
                        </div>
                        <div class="post-content" itemprop="articleBody">
                            <?php
                            $stat = Typecho_Widget::widget('Widget_Stat');
                            Typecho_Widget::widget('Widget_Contents_Post_Recent', 'pageSize='.$stat->publishedPostsNum)->to($archives);
                            $year=0; $mon=0; $i=0; $j=0;
                            $output = '<div class="archives">';
                            while($archives->next()){
                                $year_tmp = date('Y',$archives->created);
                                $mon_tmp = date('m',$archives->created);
                                $y=$year; $m=$mon;
                                if ($year > $year_tmp || $mon > $mon_tmp) {
                                    $output .= '</ul></div>';
                                }
                                if ($year != $year_tmp || $mon != $mon_tmp) {
                                    $year = $year_tmp;
                                    $mon = $mon_tmp;
                                    $output .= '<div class="archives-item"><h2>'.date('Y年m月',$archives->created).'</h2><ul class="archives_list">'; //输出年份
                                }
                                $output .= '<li>'.date('d日',$archives->created).' <a href="'.$archives->permalink .'">'. $archives->title .'</a></li>'; //输出文章
                            }
                            $output .= '</ul></div></div>';
                            echo $output;
                            ?>
                        </div>
                    </article>
                </div><!-- end #main-->
            </div><!-- end #main-->
        </div><!-- end #body -->
    </div><!-- end #wrapper -->
<?php $this->need('footer.php'); ?>